package com.lagou.dao;

import com.lagou.entity.Transaction;
import com.lagou.utils.DateUtils;
import com.lagou.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * 访问Transaction表
 */
public class TransactionDao {
    /**
     *
     */
    public int transactionRecord(Transaction transaction) throws SQLException {
        //创建对象 自动模式
        QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

        //编写sql
        String sql = "insert into transaction(cardid,tratype,tramoney,tradate) values(?,?,?,?)";

        //执行插入操作
        Object[] param = {transaction.getCardid(),transaction.getTratype(),transaction.getTramoney(),transaction.getTradate(DateUtils.getDateFormart())};
        int update = qr.update(sql, param);
        return update;
    }
}
